//index.js
//获取应用实例
const app = getApp()
const fetch = require('../../../utils/fetch.js')
Component({
  properties: {
    categoryid: Number
  },
  data: {
    checkAll: false,
    categoryName: '新品类'
  },
  ready () {
    let id = this.data.categoryid
    if (id > -1) {
      // todo 请求数据
    } else {
      // 新列表
    }
  },
  methods: {
    editName () {
      this.setData({
        editName: true
      })
    },
    modifyName (e) {
      this.setData({
        categoryName: e.detail.value
      })
    },
    confirm () {
      this.setData({
        editName: false
      })
    },
    add (e) {
      console.log('新增')
      // todo 新列表 去生成新商品之前, 异步调用新建品类, 生成一个categoryId
      // 接口调用, 还是前端生成
    },
    remove (e) {
      console.log('删除')
    },
    enable (e) {
      console.log('启用')
    },
    disable (e) {
      console.log('禁用')
    },
    checkAll () {
      this.setData({
        checkAll: !this.data.checkAll
      })
    },
    editItem (e) {
      this.triggerEvent('showdetail', e.currentTarget.dataset.goodsid)
    },
    up () {
      console.log('排序往上')
    },
    down () {
      console.log('排序往下')
    },
    back () {
      this.triggerEvent('backcommoduty')
    },
    handle () {
    }
  }
})
